package com.luo.utils;

import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;


public class getPageInfoUtil<T> {

    private int currentPage;
    private int pageSize;

    public getPageInfoUtil(HashMap<String, String> page){
        this.currentPage = Integer.parseInt(page.get("pageCurrent"));
        this.pageSize = Integer.parseInt(page.get("pageSize"));
    }

    public List<T> getPageInfo(HashMap<String, String> page, List<T> list){
            this.currentPage = Integer.parseInt(page.get("pageCurrent"));
            this.pageSize = Integer.parseInt(page.get("pageSize"));
        if(list.size()<this.currentPage*this.getPageSize()) {
            return list.subList((this.currentPage - 1) * this.pageSize, list.size());
        }
        return list.subList((this.currentPage-1)*(this.pageSize),this.currentPage*this.pageSize);
    }

    public void setCurrentPage(int currentPage){
        this.currentPage = currentPage;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageSize() {
        return pageSize;
    }
}
